*Note: This file creates the CATE graphs found in Supplementary Materials/Online Appendices - 2. Additional Figures and Tables

*Set working drive
cd "~\Dropbox\Immigration is difficult\Journal Submissions\JEPS\Replication files"

*Import data
import delimited "YouGov.csv", clear

**# Treatment condition
gen Treatment = .
replace Treatment = 0 if infotreatment == "control"
replace Treatment = 1 if infotreatment == "treatment1"
replace Treatment = 2 if infotreatment == "treatment2"

label define Tlab 0 "Control" 1 "Complex and Burdensom" 2 "Restrictive", replace

label values Treatment Tlab

	*Combined Treatment
recode Treatment (0=0 "Control") (1/2=1 "Combined Treatment"),gen(Combo)
label variable Combo "Combined Treatment"

	*Burdensom Treatment
recode Treatment (0=0 "Control") (1=1 "Burdensome Treatment") (else=.),gen(Burdensome)
label variable Burdensom "Burdensom Treatment"

	*Restrictive Treatment
recode Treatment (0=0 "Control") (2=1 "Restrictive Treatment"),gen(Restrictive)
label variable Restrictive "Restrictive Treatment"


**# Political Knowledge

*Adult Sibling of US Citizen - 3 to 10 years
*Aunt or Uncle of US Citizen - no eligible
*Doctor w/out a Job Offer - no eligible
*Famous Athlete or Artist - less than 1 year
*Nanny w/ a Job Offer - 1~3 year

gen Knowledge1 = 0
replace Knowledge1 = 1 if knowledge_adultsib == "3 to 10 Years"

gen Knowledge2 = 0
replace Knowledge2 = 1 if knowledge_aunt_unc == "Not eligible"

gen Knowledge3 = 0
replace Knowledge3 = 1 if knowledge_doctor == "Not eligible"

gen Knowledge4 = 0
replace Knowledge4 = 1 if knowledge_athlete == "Less than 1 year"

gen Knowledge5 = 0
replace Knowledge5 = 1 if knowledge_nanny == "1 to 3 years"

gen KnowSum = Knowledge1 + Knowledge2 + Knowledge3 + Knowledge4 + Knowledge5 
label variable KnowSum "Knowledge about Immigration Policy"

egen zKnowSum = std(KnowSum)

	**#Preference Index

gen DV_EasyMigration = .
label variable DV_EasyMigration "Do you think it should be easier or harder for foreigners to legally immigrate to the United States than it is currently?"

replace DV_EasyMigration = 0 if preference1 == "Much harder"
replace DV_EasyMigration = .25 if preference1 == "Harder"
replace DV_EasyMigration = .5 if preference1 == "Neither harder nor easier"
replace DV_EasyMigration = .75 if preference1 == "Easier"
replace DV_EasyMigration = 1 if preference1 == "Much easier"

gen DV_MoreMigration = .
label variable DV_MoreMigration "Do you think the number of legal immigrants from foreign countries who are permitted to come to the United States should be increased a lot, increased a little, decreased a little, or decreased a lot?"

replace DV_MoreMigration = 0 if preference2 == "Decreased a lot"
replace DV_MoreMigration = .25 if preference2 == "Decreased a little"
replace DV_MoreMigration = .5 if preference2 == "Neither increased nor decreased"
replace DV_MoreMigration = .75 if preference2 == "Increased a little"
replace DV_MoreMigration = 1 if preference2 == "Increased a lot"

gen DV_Preference = (DV_EasyMigration + DV_MoreMigration)/2 
label variable DV_Preference "Pro-Immigration Preference Index"

egen DV1 = std(DV_Preference)

	**#Belief Index
	
gen DV_BurdenBelief = .
replace DV_BurdenBelief = 0 if belief1 == "Not burdensome at all"
replace DV_BurdenBelief = .33 if belief1 == "Not very burdensome"
replace DV_BurdenBelief = .66 if belief1 == "A little burdensome"
replace DV_BurdenBelief = 1 if belief1 == "Very burdensome"

label variable DV_BurdenBelief "How burdensome do you think it is to legally immigrate to the US (in terms of time or money spent on the application process)?"

gen DV_RestrictBelief = .
replace DV_RestrictBelief = 0 if belief2 == "Very high"
replace DV_RestrictBelief = .33 if belief2 == "A little high"
replace DV_RestrictBelief = .66 if belief2 == "A little low"
replace DV_RestrictBelief = 1 if belief2 == "Very low"

label variable DV_RestrictBelief "Do you think the annual limit on the number of people who can legally immigrate to the US is high or low?"

gen DV_Belief = (DV_BurdenBelief + DV_RestrictBelief)/2 
label variable DV_Belief "Perceived Difficulty Index"

egen DV2 = std(DV_Belief)

**# Demographics

gen female = .
replace female = 0 if gender == "Male"
replace female = 1 if gender == "Female"
label variable female "Female R"

gen age = 2023-birthyr
recode age (0/39=0 "Young") (40/99=1 "Old"),gen(old)
label variable old "Old R (40+)"

gen income = .
replace income = 0 if faminc_new == "Less than $10,000"
replace income = 1 if faminc_new == "$10,000 - $19,999"
replace income = 2 if faminc_new == "$20,000 - $29,999"
replace income = 3 if faminc_new == "$30,000 - $39,999"
replace income = 4 if faminc_new == "$40,000 - $49,999"
replace income = 5 if faminc_new == "$50,000 - $59,999"
replace income = 6 if faminc_new == "$60,000 - $69,999"
replace income = 7 if faminc_new == "$70,000 - $79,999"
replace income = 8 if faminc_new == "$80,000 - $99,999"
replace income = 9 if faminc_new == "$100,000 - $119,999"
replace income = 10 if faminc_new == "$120,000 - $149,999"
replace income = 11 if faminc_new == "$150,000 - $199,999"
replace income = 12 if faminc_new == "$200,000 - $249,999"
replace income = 13 if faminc_new == "$250,000 - $349,999"
replace income = 14 if faminc_new == "$350,000 - $499,999"
replace income = 15 if faminc_new == "$500,000 or more"
label variable income "Family Income"

gen edutt = .
replace edutt = 0 if educ == "No HS"
replace edutt = 1 if educ == "High school graduate"
replace edutt = 2 if educ == "Some college"
replace edutt = 3 if educ == "2-year"
replace edutt = 4 if educ == "4=year"
replace edutt = 5 if educ == "Post-grad"
label variable edutt "Education"

gen liberalism = .
replace liberalism = 0 if ideo5 == "Very conservative"
replace liberalism = 1 if ideo5 == "Conservative"
replace liberalism = 2 if ideo5 == "Moderate"
replace liberalism = 3 if ideo5 == "Liberal"
replace liberalism = 4 if ideo5 == "Very liberal"
label variable liberalism "Ideology - Liberalism"

encode pid3,gen(ipid3)
encode race,gen(irace)

**# CATE

*Install drcate 
*Cite: Sokbae Lee & Ryo Okui & Yoon-Jae Whang & Heejun Lee, 2020. "DRCATE: Stata module to estimate and plot conditional average treatment effect functions with uniform confidence bands using a doubly robust method," Statistical Software Components S458751, Boston College Department of Economics.

*ssc install drcate

	**# Immigration Difficulty Beliefs
	
	**COMBO Treatment
*Policy Knowledge
drcate DV_Belief Combo KnowSum female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on")

graph save "CATE" "CATE_PolicyKnowledge.gph", replace

*Age
drcate DV_Belief Combo age female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_Age.gph", replace

*Income
drcate DV_Belief Combo income female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_Income.gph", replace

*Ideology
drcate DV_Belief Combo liberalism female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_Ideo.gph", replace

*Graph combine
graph combine CATE_PolicyKnowledge.gph CATE_Age.gph CATE_Income.gph CATE_Ideo.gph, note("Note: Covariates include respondents' gender, race, party ID, and education") title("Conditional Average Treatment Effect (CATE)" ///
"on Immigration Difficulty Beliefs")

graph export "~\Dropbox\Immigration is difficult\Journal Submissions\JEPS\R2\CATE_DifficultyBeliefs.png", as(png) name("Graph") replace

	**Burdensome
*Policy Knowledge
drcate DV_Belief Burdensome KnowSum female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on")

graph save "CATE" "CATE_PolicyKnowledgeB.gph", replace

*Age
drcate DV_Belief Burdensome age female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_AgeB.gph", replace

*Income
drcate DV_Belief Burdensome income female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_IncomeB.gph", replace

*Ideology
drcate DV_Belief Burdensome liberalism female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_IdeoB.gph", replace

*Graph combine - Burdensome
graph combine CATE_PolicyKnowledgeB.gph CATE_AgeB.gph CATE_IncomeB.gph CATE_IdeoB.gph, name("burdensome", replace) title("Burdensome Treatment") col(2)

	**Restrictive
*Policy Knowledge
drcate DV_Belief Restrictive KnowSum female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on")

graph save "CATE" "CATE_PolicyKnowledgeR.gph", replace

*Age
drcate DV_Belief Restrictive age female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_AgeR.gph", replace

*Income
drcate DV_Belief Restrictive income female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_IncomeR.gph", replace

*Ideology
drcate DV_Belief Restrictive liberalism female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "CATE_IdeoR.gph", replace

*Graph combine - Burdensome
graph combine CATE_PolicyKnowledgeR.gph CATE_AgeR.gph CATE_IncomeR.gph CATE_IdeoR.gph, name("restrictive", replace) title("Restrictive Treatment") col(2)

*Grand combine 

graph combine burdensome restrictive, note("Note: Covariates include respondents' gender, race, party ID, and education") title("Conditional Average Treatment Effect (CATE)" ///
"on Immigration Difficulty Beliefs")

graph export "~\Dropbox\Immigration is difficult\Journal Submissions\JEPS\R2\CATE_DifficultyBeliefs2.png", as(png) name("Graph") replace




	**# Pro-Immigration Preference
	
	**COMBO Treatment
*Policy Knowledge
drcate DV_Preference Combo KnowSum female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on")

graph save "CATE" "2CATE_PolicyKnowledge.gph", replace

*Age
drcate DV_Preference Combo age female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_Age.gph", replace

*Income
drcate DV_Preference Combo income female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_Income.gph", replace

*Ideology
drcate DV_Preference Combo liberalism female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_Ideo.gph", replace

*Graph combine

graph combine 2CATE_PolicyKnowledge.gph 2CATE_Age.gph 2CATE_Income.gph 2CATE_Ideo.gph, note("Note: Covariates include respondents' gender, race, party ID, and education") title("Conditional Average Treatment Effect (CATE)" ///
"on Pro-Immigration Preferences")

graph export "~\Dropbox\Immigration is difficult\Journal Submissions\JEPS\R2\CATE_ProImmigration.png", as(png) name("Graph") replace

	**Burdensome
*Policy Knowledge
drcate DV_Preference Burdensome KnowSum female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on")

graph save "CATE" "2CATE_PolicyKnowledgeB.gph", replace

*Age
drcate DV_Preference Burdensome age female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_AgeB.gph", replace

*Income
drcate DV_Preference Burdensome income female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_IncomeB.gph", replace

*Ideology
drcate DV_Preference Burdensome liberalism female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_IdeoB.gph", replace

*Graph combine - Burdensome
graph combine 2CATE_PolicyKnowledgeB.gph 2CATE_AgeB.gph 2CATE_IncomeB.gph 2CATE_IdeoB.gph, name("burdensome2", replace) title("Burdensome Treatment") col(2)

	**Restrictive
*Policy Knowledge
drcate DV_Preference Restrictive KnowSum female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on")

graph save "CATE" "2CATE_PolicyKnowledgeR.gph", replace

*Age
drcate DV_Preference Restrictive age female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_AgeR.gph", replace

*Income
drcate DV_Preference Restrictive income female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_IncomeR.gph", replace

*Ideology
drcate DV_Preference Restrictive liberalism female irace ipid3 edutt, ps("probit") graph("on") ci("on") ate("on") 

graph save "CATE" "2CATE_IdeoR.gph", replace

*Graph combine - Restrictive
graph combine 2CATE_PolicyKnowledgeR.gph 2CATE_AgeR.gph 2CATE_IncomeR.gph 2CATE_IdeoR.gph, name("restrictive2", replace) title("Restrictive Treatment") col(2)

*Grand combine 

graph combine burdensome2 restrictive2, note("Note: Covariates include respondents' gender, race, party ID, and education") title("Conditional Average Treatment Effect (CATE)" ///
"on Pro-Immigration Beliefs")

graph export "~\Dropbox\Immigration is difficult\Journal Submissions\JEPS\R2\CATE_ProImmigration2.png", as(png) name("Graph") replace

